layui.use('form', function () {
    var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

});

layui.use('layer', function () { //独立版的layer无需执行这一句
    var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句


    //触发事件
    var active = {
        notice: function () {
            //示范一个公告层
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                skin: 'layout-container',
                offset: 't',
                content: `   <div class="layout-container">
        <div class="layer-border">
            <div class="layer-heyue">
                <div>合约</div>
                <div>A2105</div>
            </div>
            <div class="layer-blank"></div>
            <div class="layer-date">
                <div>日期</div>
                <input type="text" class="test-item" placeholder="选择日期" style="width: 80px;">
            </div>
        </div>
        <div class="layer-border">
            <div class="layer-heyue">
                <div>期权类型</div>
                <select name="" id="">
                    <option value="看涨">看涨</option>
                    <option value="看跌">看跌</option>
                </select>
            </div>
            <div class="layer-blank"></div>
            <div class="layer-date">
                <div>标的现价</div>
                <input type="number" style="width: 80px;">
            </div>
        </div>
        <div class="layer-border">
            <div class="layer-heyue">
                <div>执行价</div>
                <input type="number" style="width: 80px;">
            </div>
            <div class="layer-blank-btn">
                <button class="computed-btn">计算</button>
            </div>
            <div class="layer-date">
                <div>交易单位： <label>吨</label> </div>
                <input type="number" style="width: 80px;">
            </div>
        </div>
        <div class="result-content">
            <div class="buy-result">
                <div class="result-title">买入</div>
                <div class="result-item">128.50 元/吨</div>
                <div class="result-item">
                    Vol(%):<label>20.45%</label>
                </div>
                <div class="result-item">
                    买入权利金:
                </div>
                <div class="result-item">
                    <label>128498.00 元</label>
                </div>
            </div>
            <div class="sell-result">
                <div class="result-title">卖出</div>
                <div class="result-item">108.73 元/吨</div>
                <div class="result-item">
                    Vol(%):<label>16.45%</label>
                </div>
                <div class="result-item">
                    卖出权利金:
                </div>
                <div class="result-item">
                    <label>103735.00 元</label>
                </div>
            </div>
        </div>
      </div>`,
                success: function () {
                    // layui.use('laydate', function () {
                    //     var laydate = layui.laydate;
                    //     laydate.render({
                    //         elem: '#datelayerbtn'
                    //         , show: true //直接显示
                    //     });
                    //     //外部事件调用
                    //     lay('#datelayerbtn').on('click', function (e) { //假设 test1 是一个按钮
                    //         laydate.render({
                    //             elem: '#datelayerbtn'
                    //             , show: true //直接显示
                    //             , closeStop: '#datelayerbtn' //这里代表的意思是：点击 test1 所在元素阻止关闭事件冒泡。如果不设定，则无法弹出控件
                    //             , trigger: 'click'
                    //         });
                    //     });

                    // });
                    layui.use('laydate', function () {
                        var laydate = layui.laydate;
                        //同时绑定多个
                        lay('.test-item').each(function () {
                            laydate.render({
                                elem: this
                                , format: 'yyyy-MM-dd'
                                , type: 'date'
                                , trigger: 'click'
                            });
                        });
                    });

                }
            });
        }
    };


    $('#buyPrice , #sellPrice').on('click', function () {
        var othis = $(this), method = othis.data('method');
        active[method] ? active[method].call(this, othis) : '';
    });
});

// 首页表头标题切换
var isPercent = false;
function typeChange() {
    if (isPercent) {
        isPercent = false;
        $('#indexBuy').html('客户买价');
        $('#indexSell').html('客户卖价');
        $('#indexBuy,#indexSell').modal(layer.msg('当前为绝对价格报价', {
            time: 800
        }));
    } else {
        isPercent = true;
        $('#indexBuy').html('客户买价%');
        $('#indexSell').html('客户卖价%');
        $('#indexBuy,#indexSell').modal(layer.msg('当前为百分比报价', {
            time: 800
        }));

    }
}
// 详情页表头标题切换
var isPercentdetail = "baifenbi";
function detailtypeChange() {
    if (isPercentdetail == "juedui") {
        isPercentdetail = "baifenbi";
        $('#updetailBuy').html('客户买价');
        $('#updetailSell').html('客户卖价');
        $('#downdetailBuy').html('客户买价');
        $('#downdetailSell').html('客户卖价');
        $('#updetailBuy,#updetailSell,#downdetailBuy,#downdetailSell').modal(layer.msg('当前为绝对价格报价', {
            time: 800
        }));

    } else if (isPercentdetail == "baifenbi") {
        isPercentdetail = "bodong";
        $('#updetailBuy').html('客户买价%');
        $('#updetailSell').html('客户卖价%');
        $('#downdetailBuy').html('客户买价%');
        $('#downdetailSell').html('客户卖价%');
        $('#updetailBuy,#updetailSell,#downdetailBuy,#downdetailSell').modal(layer.msg('当前为百分比报价', {
            time: 800
        }));

    } else if (isPercentdetail == "bodong") {
        isPercentdetail = "juedui";
        $('#updetailBuy').html('买入波动率');
        $('#updetailSell').html('卖出波动率');
        $('#downdetailBuy').html('买入波动率');
        $('#downdetailSell').html('卖出波动率');
        $('#updetailBuy,#updetailSell,#downdetailBuy,#downdetailSell').modal(layer.msg('当前为报价波动率', {
            time: 800
        }));

    }
}